<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>课程详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <style>
        body{ background-color: #F6F7F8}
        header{
            background-color: #ffffff;
            border-style: solid;
            border-color: #F6F6F6;
            border-bottom-width: 0.01rem;
        }
        header div { height: 0.35rem;  }
        .flex{display: -webkit-box; display: -webkit-flex; display: flex;}
        .not-active {
            display: none;
        }
    </style>
</head>
<body>
<div id="wrap" class="flex-wrap flex-vertical">
    <div id="main" class="flex-con">

    </div>
    <div id="footer" class="border-t" style="box-shadow: 0rem -0.03rem 0.20rem rgba(37,61,121,0.13);">
        <div id="member" class="flex not-active" style="width: 100%; height: 0.36rem; justify-content: center; align-items: center; background-color: #FFFFFF">
            <p style="font-size: 0.12rem; line-height: 0.17rem; color: #A15226; font-weight: 600;">升级金牌会员</p>
            <p style="font-size: 0.12rem; line-height: 0.17rem; color: #231313;">可与大师无限制连线问诊</p>
        </div>
        <div class="flex" style="width: 100%; height: 0.50rem;">
            <div class="flex" style="width: 50%; height: 0.50rem; background-color: #FFFFFF; justify-content: center; align-items: center;" tapmode onclick="openMasterBookingWin()">
                <p style="font-size: 0.16rem; color: #A0522C; text-align: center;">预约视频问诊</p>
            </div>
            <div class="flex" style="width: 50%; height: 0.50rem; background-color: #A0522C; justify-content: center; align-items: center;" tapmode onclick="openMasterImWin()">
                <p style="font-size: 0.16rem; color: white; text-align: center;">图文问诊</p>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common/common.js"></script>
<script type="text/javascript">
    var memberEl;
    var times = -2;
    apiready = function () {
        $api.fixTabBar($api.byId('footer'));
        memberEl = $api.byId("member");

        getRemainTimes();
    }

    function getRemainTimes() {
        api.ajax({
            url: apiUrl + '/vip/remain-times',
            tag: '/vip/remain-times',
            method: 'get',
            data: {
                values: {
                    token: $api.getStorage("token"),
                }
            }
        }, function(ret, err) {
            if (ret) {
                if (ret.code == 0) {
                    times = ret.data.times;
                    // times = 0;
                    if (times > 0) {
                        $api.removeCls(memberEl, "not-active")
                    }
                    api.openFrame({
                        name: 'masterFrame',
                        url: './masterFrame.html',
                        bgColor: 'rgba(0,0,0,0)',
                        bounces: true,
                        pageParam: {
                            master_id: api.pageParam.master_id,
                        },
                        rect: {
                            x: 0,
                            y: 0,
                            w: api.winWidth,
                            h: $api.dom('#main').offsetHeight
                        }
                    });
                } else {
                    api.toast({
                        msg: ret.err_msg,
                        duration: 2000,
                        location: 'middle'
                    });
                }
            } else {
                // api.alert({ msg: JSON.stringify(err) });
            }
        });
    }

    function openMasterBookingWin() {
        if (times != -2) {
            if (times > 0 || times == -1) {
                api.execScript({
                    frameName: 'masterFrame',
                    script: 'openMasterBookingWin();',
                });
            } else if (times == 0) {
                api.confirm({
                    title: '免费预约次数已用完',
                    msg: '开通金牌会员，与大师无限连续问诊',
                    buttons: ['取消', '立即开通']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 2) {
                        alert("页面还没写")
                    }
                });
            }
        }
    }

    function openMasterImWin() {
        if (times != -2) {
            if (times > 0 || times == -1) {
                api.execScript({
                    frameName: 'masterFrame',
                    script: 'openMasterImWin();',
                });
            } else if (times == 0) {
                api.confirm({
                    title: '免费预约次数已用完',
                    msg: '开通金牌会员，与大师无限连续问诊',
                    buttons: ['取消', '立即开通']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 2) {
                        alert("页面还没写")
                    }
                });
            }
        }
    }
</script>
